<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div id="cc_products" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'',split:true" style="height:40px;background-color:#e6edfd;">
    	<form action="" id="productChooseSearchForm" name="productChooseSearchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>商品</span></td>
				<td class="screen-n">
					<input type="text" id="choose_search_chsName" class="screen-input" onkeydown="pms.kd13('initChooseProductProducts')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initChooseProductProducts()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('productChooseSearchForm')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="chooseProductTableGrid"></table>
	</div>
</div>  
<script>
var chooseToolbar = [{
	text:'选择商品',
    iconCls:'icon-save',
    handler:function(){
    	setChooseProduct("");
    }
}];
var chooseProductsTable;
function initChooseProductProducts(){
	chooseProductsTable = $('#chooseProductTableGrid').pDataGrid({
		toolbar:chooseToolbar,
		 columns:[[
		          	  {field:'ck',checkbox:true},
		              {field:'productCode',title:'商品编号',align:'center'},
		              {field:'chsName',title:'商品名称',align:'center'},
		              {field:'productSpec',title:'规格',align:'center'},
		              {field:'stockNum',title:'库存',align:'center'},
		              {field:'packingUnit',title:'包装',align:'center'},
		              {field:'salePrice',title:'价格',align:'center'},
		              {field:'brandName',title:'品牌',align:'center'},
		              {field:'producingName',title:'生产厂家',align:'center'}
		          ]],
		    url:'<c:url value="/product/searchPageProduct.do"/>',  
		    pagination:true,
		    pageSize:30,
			singleSelect:${param.singleSelect},
		    queryParams:{
				"chsName":$('#choose_search_chsName').val()
		    },
		    onDblClickRow:function(rowIndex, rowData){
		    	setChooseProduct(rowData.productCode,rowData.salePrice,rowData.retailPrice,rowData.chsName);
			}
	}); 
}
initChooseProductProducts();

function setChooseProduct(productCode,salePrice,retailPrice,chsName){
	var param = new Object();
	if(productCode==""){
	  var datas =  chooseProductsTable.getCheckedData();
	  if(datas==null || datas.length==0){
		  alertWarning("未选中任何产品,请在需要的商品上打钩!");
		  return;
	  }
	  for(var i=0;i<datas.length;i++){
		  param['productList['+i+'].productCode']=datas[i].productCode;
		  param['productList['+i+'].salePrice']=datas[i].salePrice;
		  param['productList['+i+'].retailPrice']=datas[i].retailPrice;
		  param['productList['+i+'].chsName']=datas[i].chsName;
	  }
	}else{
		//单个
		param['productList[0].productCode']=productCode;
		param['productList[0].salePrice']=salePrice;
		param['productList[0].chsName']=chsName;
		param['productList[0].retailPrice']=retailPrice;
	}
	$.messager.confirm('确认信息', '确认将勾选的商品加入前页?', function(r){
		if (r){
			 //活动明细也 用receiveProduct回调 
			receiveProduct(param);

			
		}
	});
   
}


</script>
